tsim-0.7
),
Java interface (TSim
),
2 (2.c
)
and the track used for the programming task at HUT (track
)
can be downloaded here.make
in the tsim-0.7
directory. This will generate an
executable called tsim
(or tsim.exe
on Windows Cygwin)
in that directory. tsim should compile without
modification on Linux and Cygwin. You must edit the C compiler flags in
the Makefile
to compile on Solaris, FreeBSD and Irix.
tsim can use an external sound player for sound effects; by default mpg123
is used on Unix and Sound Recorder on Windows. The supplied sound
effects are public domain samples converted to MPEG Layer 3
WAVs.tsim
<filename>track
.tsim
<width>
<height>tsim
bitmapDir
./bitmaps
soundDir
./sounds
timeoutInterval
0.1
acceleration
5.0
playCmd
%s
.sndrec32
/play /close /embedding "%s"
mpg123
"%s"
foreground
black
background
white
~/.Xresources
.
They
can also be set using xrdb
-merge
. The format used in
both
cases is:tsim*
<resource>:
<value>xrdb -merge
and enter the following:tsim*playCmd:artsdsp mpg123
"%s"
TSim/doc
).
The Java interface is typically used through the utility 2
(included in the tsim package) as follows:./2 "cd tsim-0.7; ./tsim
../track-sensors" "java
trains.Train"
2 can be compiled using the
following command line (assuming you have gcc
installed):gcc -o 2 2.c
System.in
and System.out
),
as this will interfere with the connection between tsim and the tsim
Java interface. Standard error (System.err
)
can be used for debugging.TSim.TSimInterface
class. To get an instance of this class, call TSim.TSimFactory.getTSimInterface()
.
It is important that you only call this once,
as creating multiple running tsim interfaces in the same process will
cause communication errors.TSimInterface
has three primary methods through which the trains are controlled:public void setSpeed(int trainId, int speed)This method sets the speed of the train identified by
trainId
to speed
.
The speed is measured in pixels/second. A negative speed value causes the train to travel backwards. You may not set a negative speed when the train is travelling forwards or a positive speed when the train is travelling backwards; the train must be stopped in order to change direction.public void setSwitch(int xPos, int yPos, int switchPos)This method sets the state of the switch at (
xPos
,
yPos
)
to
switchPos
.
switchPos
can be either TSimInterface.SWITCH_LEFT
or TSimInterface.SWITCH_RIGHT
.
public SensorEvent getSensor(int trainId)This method waits until a sensor event is received from train
trainId
and returns the sensor event. Sensor events are generated when a train
enters or exits
a square containing a sensor. Sensor events can be examined through the
following SensorEvent
methods:public int getXpos()This method returns the X position of the sensor.
public int getYpos()This method returns the Y position of the sensor.
public int getStatus()This method returns the status of the sensor:
SensorEvent.ACTIVE
if
a train has entered the sensor's square and SensorEvent.INACTIVE
if
a train has left the sensor's square.
public int getTrainId()This method returns the id of the train.
TSim/doc/index.html
in the tsim package.